/**
 * @Author: easten
 * @Created: 2024-07-21 15:28:36
 * @Description: 数据字典接口
 *
 */
import { SysDict } from "_common/entity/sys/SysDict";
import { createRequest, RequestMethod } from "_common/request";
import { AxiosInstance } from "axios";

export class ApiDict {
  /**
   * @description 请求实例
   * @type {RequestMethod}
   * @memberof ApiDevice
   * */
  request: RequestMethod;
  url: string = "api/sys/dict";

  /**
   * @description 构造函数
   * @param config axios 配置
   */
  public constructor(instance: AxiosInstance) {
    // axios 实例化
    this.request = createRequest(instance);
  }

  createDict(data: SysDict) {
    return this.request.post<boolean>(this.url + "/create", data);
  }

  /** 更新数据字典 */
  updateDict(data: SysDict) {
    return this.request.put<boolean>(this.url + "/update", data);
  }

  /** 删除数据字典 */
  deleteDict(id: number) {
    return this.request.delete<boolean>(this.url + "/delete/" + id);
  }

  /** 获取数据字典信息 */
  getDictInfo(id: number) {
    return this.request.get<SysDict>(this.url + "/get-dict", { id });
  }

  /** 获取数据字典列表 */
  getDictList(params: any) {
    return this.request.get<SysDict[]>(this.url + "/get-list", params);
  }

  // 获取数据字典分页列表
  getPageList(params: any) {
    return this.request.get<any>(this.url + "/get-page", params);
  }
  // 获取子集
  getChildren(code: string) {
    return this.request.get<any>(this.url + "/get-children/" + code);
  }
}
